import java.util.ArrayList;
import java.util.List;

public class RemoveElement {
    public int removeElement(int[] nums, int val) {
        int a = nums.length;
        //两个想法：a、将val替换为0，返回不为0的数量；b、直接删除val
        //可是怎么从数组中删除一个数呢？
        List<Integer> list = new ArrayList<>();
        for (int j = 0;j < nums.length;j++){
            list.add(nums[j]);
        }
        int b = list.size();
        for (int i = 0; i < b; i++) {
            if (list.get(i) == val){
                list.set(i,null);
            }
        }
        int size = 0;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) != null){
                size++;
            }
        }
        System.out.println(list);
        return size;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,2,2,3,0,4,2};
        RemoveElement r = new RemoveElement();
        int a = r.removeElement(nums,3);
        System.out.println(a);
    }
}
